home *** CD-ROM | disk | FTP | other *** search
- ///////////////////////////////////////////////////////////////////////////////
- //
- // Hector.cxx - This is the Hector 1600 CPU class
- //
- // By: Bradford W. Mott
- // December 3,1993
- //
- ///////////////////////////////////////////////////////////////////////////////
-
- #include "Tools.hxx"
- #include "RegInfo.hxx"
- #include "Hector.hxx"
-
- ///////////////////////////////////////////////////////////////////////////////
- // Hector 1600 Class constructor
- ///////////////////////////////////////////////////////////////////////////////
- Hector::Hector(AddressSpace *addr)
- : BasicCPU(
- "Hector 1600", // Name of the CPU
- 2, // Granularity in bytes
- 1, // Number of address spaces
- addr, // Array of address spaces
- "{InstructionAddress 4} {Mnemonic 35}", // Execution trace record
- "InstructionAddress Mnemonic" // Default trace entries
- )
- {
- // Allocate a data path
- data_path = new DataPath(this);
-
- // Allocate a control unit
- control_unit = new ControlUnit(*data_path);
-
- // Reset the system
- Reset();
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // The Hector 1600 Class destructor
- ///////////////////////////////////////////////////////////////////////////////
- Hector::~Hector()
- {
- // Deallocate control unit
- delete control_unit;
-
- // Deallocate data path
- delete data_path;
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // Perform a system reset
- ///////////////////////////////////////////////////////////////////////////////
- void Hector::Reset()
- {
- // Reset all of the attached devices
- address_space[0].Reset();
-
- // Init the Flags register with interrupts turned off
- data_path->alu.SetFlags(I_FLAG);
-
- // Reset the data path's signals
- data_path->ResetSignals();
-
- // Clear the data path's statistics
- data_path->ClearStatistics();
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // Return the value in the program counter
- ///////////////////////////////////////////////////////////////////////////////
- unsigned long Hector::ValueOfProgramCounter()
- {
- return(data_path->register_set.GetRegister(PC));
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // Return the name of the program counter
- ///////////////////////////////////////////////////////////////////////////////
- char* const Hector::NameOfProgramCounter()
- {
- return(data_path->register_set.GetRegisterData(PC).name);
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // Set the named register to the given value
- ///////////////////////////////////////////////////////////////////////////////
- void Hector::SetRegister(String name, String hex_value)
- {
- unsigned int value;
-
- // Convert Hex String to an integer value
- value=StringToInt(hex_value);
-
- // See if they are setting the ALU's flags
- if(name=="FLAGS")
- {
- data_path->alu.SetFlags(value);
- return;
- }
-
- // See if they are setting any of the register file's registers
- for(int t=0;t<data_path->register_set.NumberOfUserRegisters();++t)
- {
- if(name==data_path->register_set.GetRegisterData(t).name)
- {
- data_path->register_set.SetRegister(t,value);
- break;
- }
- }
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // Clear the CPU's Statistics
- ///////////////////////////////////////////////////////////////////////////////
- void Hector::ClearStatistics()
- {
- // Tell the data path object to clear the statistics
- data_path->ClearStatistics();
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // Build the statistics list for the StatisticalInformationList object
- ///////////////////////////////////////////////////////////////////////////////
- void Hector::BuildStatisticalInformationList(StatisticalInformationList* list)
- {
- String entry;;
-
- // Add the number of reads
- entry = "# Reads: ";
- entry += IntToDecimal(data_path->NumberOfReads(),8);
- list->Append(entry);
-
- // Add the number of writes
- entry = "# Writes: ";
- entry += IntToDecimal(data_path->NumberOfWrites(),8);
- list->Append(entry);
-
- // Add the number of cycles
- entry = "# Cycles: ";
- entry += IntToDecimal(data_path->NumberOfCycles(),8);
- list->Append(entry);
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // Build the register list for the RegisterInformationList object
- ///////////////////////////////////////////////////////////////////////////////
- void Hector::BuildRegisterInformationList(RegisterInformationList *list)
- {
- int t;
- String value;
-
- // Add all of the register's in the register file to the list
- for(t=0;t<data_path->register_set.NumberOfUserRegisters();++t)
- {
- value=IntToString(data_path->register_set.GetRegister(t),4);
- list->Append(data_path->register_set.GetRegisterData(t).name,
- value, data_path->register_set.GetRegisterData(t).description);
- }
-
- // Add the FLAGS register in the ALU to the list
- value=IntToString(data_path->alu.GetFlags(),4);
- list->Append("FLAGS",value,"FLAGS: CVNZI-----------");
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // Execute the next instruction
- ///////////////////////////////////////////////////////////////////////////////
- const char* Hector::ExecuteInstruction(String& trace_record, int trace_flag)
- {
- const char* error_message;
-
- error_message=control_unit->ExecuteInstruction(trace_record, trace_flag);
- return(error_message);
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // Handle an interrupt request from a device
- ///////////////////////////////////////////////////////////////////////////////
- void Hector::InterruptRequest(BasicDevice* device, int level)
- {
- }
-
-